package com.kgcx.coupon.rabbitmq.producer;

import com.alibaba.fastjson.JSONObject;
import com.kgcx.common.api.ApiContant;
import com.kgcx.common.rabbitmq.bean.Message;
import com.kgcx.common.rabbitmq.consts.ExchangeConst;
import com.kgcx.common.rabbitmq.consts.RoutingKeyConst;
import com.kgcx.coupon.domain.Comment;
import com.kgcx.coupon.domain.Complain;
import com.kgcx.coupon.domain.Punish;
import com.kgcx.coupon.domain.RatedDriver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 何凯
 * @version 0.1
 * @description
 * @time 2017/12/7 15:38
 * @since 0.1
 */
@Slf4j
@Component
public class OpcProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送评价消息给监管平台
     * @param comment
     */
     public void sendComment(Comment comment) {
        log.info(String.format("查询评价信息成功的MQ消息，评价信息id[%s]。", comment.getKid()));
        Message msg = Message.buildMessage(ApiContant.COMMENT, Message.FLAG_ADD, comment);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON,JSONObject.toJSONString(msg));
        log.info(String.format("msgId[%s]。", msg.getId()));
     }
     /**
     * 发送处罚消息给监管平台
     * @param punish
     */
     public void sendPunish(Punish punish) {
        log.info(String.format("查询处罚信息成功的MQ消息，投诉信息id[%s]。", punish.getKid()));
        Message msg = Message.buildMessage(ApiContant.PUNISH, Message.FLAG_ADD, punish);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON,JSONObject.toJSONString(msg));
        log.info(String.format("msgId[%s]。", msg.getId()));
     }
     /**
     * 发送司机信誉消息给监管平台
     * @param ratedDriver
     */
     public void sendRatedDriver(RatedDriver ratedDriver) {
        log.info(String.format("查询司机信誉信息成功的MQ消息，司机信誉信息id[%s]。", ratedDriver.getKid()));
        Message msg = Message.buildMessage(ApiContant.RATED, Message.FLAG_ADD, ratedDriver);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON,JSONObject.toJSONString(msg));
        log.info(String.format("msgId[%s]。", msg.getId()));
     }
      /**
     * 发送修改司机信誉消息给监管平台
     * @param ratedDriver
     */
     public void sendRatedUpdateDriver(RatedDriver ratedDriver) {
        log.info(String.format("查询司机信誉信息成功的MQ消息，司机信誉信息id[%s]。", ratedDriver.getKid()));
        Message msg = Message.buildMessage(ApiContant.RATED, Message.FLAG_UPDATE, ratedDriver);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON,JSONObject.toJSONString(msg));
        log.info(String.format("msgId[%s]。", msg.getId()));
     }
     /**
     * 发送投诉消息给监管平台
     * @param complain
     */
     public void sendComplain(Complain complain) {
        log.info(String.format("查询投诉信息成功的MQ消息，投诉信息id[%s]。", complain.getKid()));
        Message msg = Message.buildMessage(ApiContant.COMPLAIN, Message.FLAG_ADD, complain);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON,JSONObject.toJSONString(msg));
        log.info(String.format("msgId[%s]。", msg.getId()));
     }
}
